import router from '@/router'
import HomeView from '@/views/HomeView.vue'

export async function activeRouter(permList){
    let root = {
        path: '/',
        name: '首页',
        component: HomeView,
        redirect: '/home',
        children: [],
    }

    permList.forEach(p1 => {
        if (p1.perms == null) {
            let obj = {
                path: p1.visitPath,
                name: p1.path,
                meta: {name: p1.name},
                component: () => import("@/views/" + p1.path),
            };
            console.log("一级:", obj);
            root.children.push(obj);
        } else {
            p1.perms.forEach(p2 => {
                let obj = {
                    path: p2.visitPath,
                    name: p2.path,
                    meta:{name: p2.name},
                    component: ()=> import("@/views/"+ p2.path),
                }
                console.log("二级:",obj)
                root.children.push(obj);
            });
        }
    });
    router.addRoute(root);
}